﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseSet.Data;
using BaseSet.Logic;
using BaseSet.Entity;
using BaseSet.Framework;
using BaseSet.Entity.Common;
using BaseSet.Entity.Common.Text;
using BaseSet;
using System.Data;

namespace WebSite.Admin.NewsManager
{
    public partial class NewsAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindNewsType();
            }
        }

        #region 提交
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            News ninfo = new News();
            NewsHelper nhelper = new NewsHelper();
            ninfo.NewsTypeID = ddlNewsType.SelectedValue;
            ninfo.Title = txtTitle.Text.Trim();
            ninfo.NewsContent = txtContent.Value.Trim();
            
            nhelper.AddNews(ninfo);

            Tools.AlertAndRedirect("添加成功！", "NewsManager.aspx");
        }
        #endregion

        #region 返回
        protected void ReturnBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("NewsManager.aspx");
        }
        #endregion

        #region 加载类别
        private void BindNewsType()
        {
            NewsTypeHelper nhelper = new NewsTypeHelper();

            List<NewsType> list = nhelper.GetNewsTypes();
            ddlNewsType.DataSource = list;
            ddlNewsType.DataTextField = "NewsTypeName";
            ddlNewsType.DataValueField = "ID";
            ddlNewsType.DataBind();

            ListItem li = new ListItem();
            li.Value = "-1";
            li.Text = "-请选择-";
            ddlNewsType.Items.Insert(0, li);
        }
        #endregion
    }
}